package com.dayangxiaoen.pms.controller;

import com.dayangxiaoen.pms.common.aop.LogAnnotation;
import com.dayangxiaoen.pms.dto.ProductDTO;
import com.dayangxiaoen.pms.dto.SearchDTO;
import com.dayangxiaoen.pms.dto.VerifyResultDTO;
import com.dayangxiaoen.pms.po.Product;
import com.dayangxiaoen.pms.service.ProductService;
import com.dayangxiaoen.pms.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author dayangxiaoen
 */

@RestController
@RequestMapping("product")
@Slf4j
public class ProductController {

    /**
     * localhost:8088/product/lists
     * 查询所有商品
     */

    @Autowired
    private ProductService productService;

    /**
     * 显示全部商品
     * @return
     */
    @GetMapping("lists")
    @LogAnnotation(module = "product", operator = "显示全部商品信息")
    public Result finadAllProducts(){
        return productService.findAllProduct();
    }


    @GetMapping("lists/search")
    @LogAnnotation(module = "product", operator = "根据搜素条件显示所有商品信息")
    public Result finadAllProductsWithCondition(SearchDTO searchDTO){
        return productService.finadAllProductsWithCondition(searchDTO);
    }

    @GetMapping("detail/{id}")
    @LogAnnotation(module = "product", operator = "根据ID查询商品详细信息")
    public Result finadDetailProductsById(@PathVariable("id") Long id){
        return productService.findDetailProductById(id);
    }

    @PostMapping("add")
    @LogAnnotation(module = "product", operator = "添加商品")
    public Result addProduct(@RequestBody ProductDTO productDTO){
        return productService.addProductWithProductDTO(productDTO);
    }

    @PostMapping("update")
    @LogAnnotation(module = "product", operator = "更新商品")
    public Result updateProduct(@RequestBody ProductDTO productDTO){
        return productService.updateProductWithProductDTO(productDTO);
    }

    @PostMapping("verify/{id}")
    @LogAnnotation(module = "product", operator = "根据指定id对商品进行发起审核")
    public Result productVerify(@PathVariable("id") Long id){
        return productService.productVerify(id);
    }

    @PostMapping("online/{id}")
    @LogAnnotation(module = "product", operator = "根据指定id对商品进行上线")
    public Result productOnLine(@PathVariable("id") Long id){
        return productService.productOnLine(id);
    }

    @PostMapping("offline/{id}")
    @LogAnnotation(module = "product", operator = "根据指定id对商品进行下线")
    public Result productOffLine(@PathVariable("id") Long id){
        return productService.productOffLine(id);
    }

    @PostMapping("verifyResult")
    @LogAnnotation(module = "product", operator = "根据指定id修改商品状态")
    public Result updateProductState(@RequestBody VerifyResultDTO verifyResultDTO){
        return productService.updateProductState(verifyResultDTO);
    }

}
